<!DOCTYPE html>
<html lang="en">

<head>
    <style>

    </style>
</head>

<body>
    <input type="text">
    <button>求和</button>
</body>
<script>
    var inp = document.getElementsByTagName('input')[0]
    var button = document.getElementsByTagName('button')[0]
    // let num=0
    button.onclick = function () {
        // console.log(inp.value); 
        let num = 0
        let arr = inp.value.split(',')
        //split(',')截取需要过滤的数字
        // console.log(arr);
        arr.forEach(i => {
            
            num += i*1
        })
        alert(num)
    }
</script>

</html>